import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    plugins: [
        vue(),
        legacy({
            targets: ['defaults', 'not IE 11']
        }),
        AutoImport({
            resolvers: [ElementPlusResolver()]
        }),
        Components({
            resolvers: [ElementPlusResolver()]
        }),
        createSvgIconsPlugin({
            // 指定要缓存.svg文件的文件夹
            iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
            // Specify symbolId format
            symbolId: 'icon-[dir]-[name]'
        })
    ],
    // 开发环境服务器配置
    server: {
        cors: true,
        proxy: {
            '/proxy': {
                // target: 'https://t-h5-mall.wens.com.cn/',
                // target: 'https://test-sit-cangqiong.wens.com.cn/',
                target: 'https://t-mall.wens.com.cn/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/proxy/, '')
            },
            '/ngbProxy': {
                target: 'https://t-csp.wens.com.cn/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/ngbProxy/, '')
            },
            '/ierp': {
                target: 'http://10.33.63.26:8089/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/ierp/, '')
            }
        }
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    }
})
